<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto Serif SC:300,300italic,400,400italic,700,700italic|Roboto Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-bounce.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"zhiruozzy.cn","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"default"},"back2top":{"enable":"truw","sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="HTTP协议协议规定了两部分的内容，分别是请求报文和响应报文">
<meta property="og:type" content="article">
<meta property="og:title" content="HTTP自学笔记">
<meta property="og:url" content="http://zhiruozzy.cn/2022/03/27/HTTP/index.html">
<meta property="og:site_name" content="芷若">
<meta property="og:description" content="HTTP协议协议规定了两部分的内容，分别是请求报文和响应报文">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://zhiruozzy.cn/img/HTTP/image-20220327104852899.png">
<meta property="og:image" content="http://zhiruozzy.cn/img/HTTP/image-20220327105318272.png">
<meta property="og:image" content="http://zhiruozzy.cn/img/HTTP/image-20220327140133597.png">
<meta property="article:published_time" content="2022-03-27T01:36:26.000Z">
<meta property="article:modified_time" content="2022-04-07T14:08:35.375Z">
<meta property="article:author" content="芷若">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://zhiruozzy.cn/img/HTTP/image-20220327104852899.png">

<link rel="canonical" href="http://zhiruozzy.cn/2022/03/27/HTTP/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>HTTP自学笔记 | 芷若</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --><link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css">
<link rel="stylesheet" href="/css/prism-line-numbers.css" type="text/css"></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">芷若</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-主页">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>主页</a>

  </li>
        <li class="menu-item menu-item-关于">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-标签">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-目录">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>目录</a>

  </li>
        <li class="menu-item menu-item-归档">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container"></div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="algolia-results">
  <div id="algolia-stats"></div>
  <div id="algolia-hits"></div>
  <div id="algolia-pagination" class="algolia-pagination"></div>
</div>

      
    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/zhiruozzy" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://zhiruozzy.cn/2022/03/27/HTTP/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/touxiang.jpg">
      <meta itemprop="name" content="芷若">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="芷若">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          HTTP自学笔记
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-03-27 09:36:26" itemprop="dateCreated datePublished" datetime="2022-03-27T09:36:26+08:00">2022-03-27</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-04-07 22:08:35" itemprop="dateModified" datetime="2022-04-07T22:08:35+08:00">2022-04-07</time>
              </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="HTTP协议"><a href="#HTTP协议" class="headerlink" title="HTTP协议"></a>HTTP协议</h2><p>协议规定了两部分的内容，分别是请求报文和响应报文</p>
<span id="more"></span>

<h2 id="HTTP报文"><a href="#HTTP报文" class="headerlink" title="HTTP报文"></a>HTTP报文</h2><h3 id="请求报文"><a href="#请求报文" class="headerlink" title="请求报文"></a>请求报文</h3><p>请求报文的的格式为：<strong>请求行  － 请求头 －空行 - 请求数据</strong></p>
<h4 id="请求行"><a href="#请求行" class="headerlink" title="请求行"></a>请求行</h4><p>由<strong>请求方法字段</strong>，<strong>URL字段</strong>和<strong>HTTP协议版本字段</strong>  三个字段构成</p>
<ul>
<li>请求方法：常见的有GET(请求指定的页面，服务器返回具体的内容数据）、POST（提交数据，如提交表单）、PUT（更新和修改数据）等，浏览器在向服务器发送请求的时候必须指明请求类型</li>
<li>URL：表示请求所针对的资源</li>
<li>协议版本：让发送方指示消息的格式和理解后续HTTP通信的能力</li>
</ul>
<p>示例：<code>GET http://www/w3/org/pub.html HTTP/1.1</code></p>
<h4 id="请求头"><a href="#请求头" class="headerlink" title="请求头"></a>请求头</h4><table>
<thead>
<tr>
<th>请求头字段</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>Accept</td>
<td>客户端可接受的MIME类型</td>
</tr>
<tr>
<td>Content-Type</td>
<td>数据属于什么类型，如js,c++,html,text格式</td>
</tr>
<tr>
<td>User-Agent</td>
<td>发出请求的用户信息，如用户使用的什么客户端</td>
</tr>
<tr>
<td>Cookie</td>
<td>客户端保存服务器返回的数据，如保存用户身份信息</td>
</tr>
<tr>
<td>Connection</td>
<td>表示处理完这次请求后是否断开链接</td>
</tr>
</tbody></table>
<h4 id="请求数据"><a href="#请求数据" class="headerlink" title="请求数据"></a>请求数据</h4><p>若方法字段是GET，则此项为空，没有数据。若方法字段是POST，则放的是提交的数据。</p>
<p>示例：<code>user=admin&amp;password=123456</code></p>
<p>请求行 － 通用信息头 － 请求头 － 实体头 － 报文主体</p>
<h4 id="示例："><a href="#示例：" class="headerlink" title="示例："></a>示例：</h4><p><strong>1. GET</strong></p>
<figure class="highlight jsp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//请求行</span></span><br><span class="line"></span><br><span class="line">GET /hello/index.jsp HTTP/<span class="number">1.1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//请求头部</span></span><br><span class="line"></span><br><span class="line">Host: localhost</span><br><span class="line">User-Agent: Mozilla/<span class="number">5.0</span> (Windows NT <span class="number">5.1</span>; rv:<span class="number">5.0</span>) Gecko/<span class="number">20100101</span> Firefox/<span class="number">5.0</span></span><br><span class="line">Accept:text/html,application/xhtml+xml,application/xml;q=<span class="number">0.9</span>,*<span class="comment">/*;q=0.8</span></span><br><span class="line"><span class="comment">Accept-Language: zh-cn,zh;q=0.5</span></span><br><span class="line"><span class="comment">Accept-Encoding: gzip, deflate</span></span><br><span class="line"><span class="comment">Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7</span></span><br><span class="line"><span class="comment">Connection: keep-alive</span></span><br><span class="line"><span class="comment">Cookie: JSESSIONID=369766FDF6220F7803433C0B2DE36D98</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">//空行</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">//因为GET没有正文，所以下面为空</span></span><br></pre></td></tr></table></figure>

<p><strong>2.POST</strong></p>
<figure class="highlight jsp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 请求行</span></span><br><span class="line"></span><br><span class="line">POST /hello/index.jsp HTTP/<span class="number">1.1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//请求头</span></span><br><span class="line"></span><br><span class="line">Host: localhost</span><br><span class="line">User-Agent: Mozilla/<span class="number">5.0</span> (Windows NT <span class="number">5.1</span>; rv:<span class="number">5.0</span>) Gecko/<span class="number">20100101</span> Firefox/<span class="number">5.0</span></span><br><span class="line">Accept:text/html,application/xhtml+xml,application/xml;q=<span class="number">0.9</span>,*<span class="comment">/*;q=0.8</span></span><br><span class="line"><span class="comment">Accept-Language: zh-cn,zh;q=0.5</span></span><br><span class="line"><span class="comment">Accept-Encoding: gzip, deflate</span></span><br><span class="line"><span class="comment">Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7</span></span><br><span class="line"><span class="comment">Connection: keep-alive</span></span><br><span class="line"><span class="comment">Referer: http://localhost/hello/index.jsp</span></span><br><span class="line"><span class="comment">Cookie: JSESSIONID=369766FDF6220F7803433C0B2DE36D98</span></span><br><span class="line"><span class="comment">Content-Type: application/x-www-form-urlencoded </span></span><br><span class="line"><span class="comment">Content-Length: 14 </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">// 这里是空行</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">//POST有请求正文</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">username=hello</span></span><br></pre></td></tr></table></figure>



<h3 id="响应报文"><a href="#响应报文" class="headerlink" title="响应报文"></a>响应报文</h3><p>响应报文的的格式为:状态行 －  响应头 － 空行  -  响应正文</p>
<h4 id="状态行"><a href="#状态行" class="headerlink" title="状态行"></a>状态行</h4><p>状态行由协议版本。状态码，原因短语构成，每个元素由空格分隔</p>
<p>示例：<code>HTTP/1.1 200 OK</code></p>
<ul>
<li><p>协议版本：让发送方指示消息的格式和理解后续HTTP通信的能力</p>
</li>
<li><p>状态码：一个3位整数结果码，用于向用户返回操作结果</p>
<p>常见状态码</p>
<table>
<thead>
<tr>
<th>状态码</th>
<th>状态码说明</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>1XX</td>
<td>请求被接收</td>
<td>100 Continue</td>
<td>请求被接收，继续执行</td>
</tr>
<tr>
<td>2XX</td>
<td>请求成功</td>
<td>200 OK</td>
<td>成功，有响应消息体</td>
</tr>
<tr>
<td></td>
<td></td>
<td>201 Created</td>
<td>资源创建成功</td>
</tr>
<tr>
<td></td>
<td></td>
<td>204 No Content</td>
<td>成功，没有响应的消息体</td>
</tr>
<tr>
<td>3XX</td>
<td>进一步操作需要被执行</td>
<td>301 Moved Permanently</td>
<td>目标资源被分配进新的URL</td>
</tr>
<tr>
<td>4XX</td>
<td>请求错误</td>
<td>400 Bad Request</td>
<td>请求消息体错误，消息体中有错误描述</td>
</tr>
<tr>
<td></td>
<td></td>
<td>401 Unauthorized</td>
<td>授权失败，如证书不匹配</td>
</tr>
<tr>
<td></td>
<td></td>
<td>403 Forbidden</td>
<td>禁止访问</td>
</tr>
<tr>
<td></td>
<td></td>
<td>404 Not Found</td>
<td>找不到请求的梓员</td>
</tr>
<tr>
<td>5XX</td>
<td>服务端错误</td>
<td>500 Internal Server Error</td>
<td>服务器内部错误</td>
</tr>
<tr>
<td></td>
<td></td>
<td>501 Not Implement</td>
<td>功能未实现</td>
</tr>
</tbody></table>
</li>
</ul>
<h4 id="响应头"><a href="#响应头" class="headerlink" title="响应头"></a>响应头</h4><table>
<thead>
<tr>
<th>响应头字段</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>Content-Encoding</td>
<td>文档的编码（Encode）方法</td>
</tr>
<tr>
<td>Allow</td>
<td>服务器支持哪些请求方法（如GET、POST等）。</td>
</tr>
<tr>
<td>Content-Length</td>
<td>表示内容长度</td>
</tr>
<tr>
<td>Content-Type</td>
<td>表示后面的文档属于什么MIME类型</td>
</tr>
<tr>
<td>Date</td>
<td>当前的GMT时间</td>
</tr>
<tr>
<td>Last-Modified</td>
<td>文档的最后改动时间</td>
</tr>
</tbody></table>
<h2 id="端口号"><a href="#端口号" class="headerlink" title="端口号"></a>端口号</h2><p>端口</p>
<p>端口分为物理端口和软件端口</p>
<p><strong>物理端口</strong>：如交换机和路由器上面插网线的口就叫做物理端口</p>
<p><img src="/../img/HTTP/image-20220327104852899.png" alt="image-20220327104852899"></p>
<p><strong>软件端口</strong>：指软件与服务器的接口，是操作系统模拟出来的。端口相当于身份证，保证了信息不会发错。分为了服务器端口和用户端的端口</p>
<p><strong>查看端口号</strong>：</p>
<p>在检查-网络中可以查看</p>
<p><img src="/../img/HTTP/image-20220327105318272.png" alt="image-20220327105318272"></p>
<p>HTTP服务器，默认的端口号为80</p>
<p>HTTPS服务器，默认的端口号为443</p>
<p>HTTP是应用层协议，是建立在传输层TCP协议之上的</p>
<p><img src="/../img/HTTP/image-20220327140133597.png" alt="image-20220327140133597"></p>
<h2 id="请求方法"><a href="#请求方法" class="headerlink" title="请求方法"></a>请求方法</h2><p>请求方法一共有9种</p>
<table>
<thead>
<tr>
<th align="left">序号</th>
<th align="left">方法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">1</td>
<td align="left">GET</td>
<td align="left">请求指定的页面信息，并返回实体主体。</td>
</tr>
<tr>
<td align="left">2</td>
<td align="left">HEAD</td>
<td align="left">类似于 GET 请求，只不过返回的响应中没有具体的内容，用于获取报头</td>
</tr>
<tr>
<td align="left">3</td>
<td align="left">POST</td>
<td align="left">向指定资源提交数据进行处理请求（例如提交表单或者上传文件）。</td>
</tr>
<tr>
<td align="left">4</td>
<td align="left">PUT</td>
<td align="left">从客户端向服务器传送的数据取代指定的文档的内容。</td>
</tr>
<tr>
<td align="left">5</td>
<td align="left">DELETE</td>
<td align="left">请求服务器删除指定的页面。</td>
</tr>
<tr>
<td align="left">6</td>
<td align="left">CONNECT</td>
<td align="left">HTTP&#x2F;1.1 协议中预留给能够将连接改为管道方式的代理服务器。</td>
</tr>
<tr>
<td align="left">7</td>
<td align="left">OPTIONS</td>
<td align="left">允许客户端查看服务器的性能。</td>
</tr>
<tr>
<td align="left">8</td>
<td align="left">TRACE</td>
<td align="left">回显服务器收到的请求，主要用于测试或诊断。</td>
</tr>
<tr>
<td align="left">9</td>
<td align="left">PATCH</td>
<td align="left">是对 PUT 方法的补充，用来对已知资源进行局部更新 。</td>
</tr>
</tbody></table>
<p>直接在浏览器的地址栏中输入网址，默认属于get请求</p>
<p>一般使用表单提交请求，默认属于post请求</p>
<p>GET和POST的区别：</p>
<ol>
<li><p>get是用来从服务器上获得数据的，而post是向服务器上传递数据的</p>
</li>
<li><p>get会将请求的数据会附在URL之后，即把数据放在HTTP协议头中，用？来分割URL和传输数据，用&amp;来分隔各个参数。如下面这个链接：</p>
<p><a target="_blank" rel="noopener" href="https://search.bilibili.com/all?keyword=http%EF%BF%BD&amp;from_source=webtop_search&amp;spm_id_from=333.788&amp;page=3">https://search.bilibili.com/all?keyword=http%E5%8D&amp;from_source=webtop_search&amp;spm_id_from=333.788&amp;page=3</a></p>
<p>如果数据是英文或者英文字母，则原样显示，如果是空格，则以+显示，如果是中文或其他字符，则将字符串用BASE64编码。即如果用GET提交数据，用户名和密码将会以明文出现在URL中。</p>
<p>post将表单中的数据放在form的数据体中，按照变量和值的对应方式，传递到action所指向的URL中</p>
</li>
<li><p>get的请求可被缓存，可被保留在浏览器的历史记录中，可被收藏为书签，而post不会，所以get的安全性差，因为发送的数据是URL的一部分</p>
</li>
<li><p>因为get是向URL中添加数据，而URL的长度是有限的（最大2048个字符），多以get的数据长度是有限的，而post的数据不限长度</p>
</li>
</ol>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2022/03/23/flex%E5%B8%83%E5%B1%80/" rel="prev" title="flex布局">
      <i class="fa fa-chevron-left"></i> flex布局
    </a></div>
      <div class="post-nav-item">
    <a href="/2022/03/27/Ajex/" rel="next" title="Ajex自学笔记">
      Ajex自学笔记 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#HTTP%E5%8D%8F%E8%AE%AE"><span class="nav-number">1.</span> <span class="nav-text">HTTP协议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HTTP%E6%8A%A5%E6%96%87"><span class="nav-number">2.</span> <span class="nav-text">HTTP报文</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AF%B7%E6%B1%82%E6%8A%A5%E6%96%87"><span class="nav-number">2.1.</span> <span class="nav-text">请求报文</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AF%B7%E6%B1%82%E8%A1%8C"><span class="nav-number">2.1.1.</span> <span class="nav-text">请求行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AF%B7%E6%B1%82%E5%A4%B4"><span class="nav-number">2.1.2.</span> <span class="nav-text">请求头</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AF%B7%E6%B1%82%E6%95%B0%E6%8D%AE"><span class="nav-number">2.1.3.</span> <span class="nav-text">请求数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%A4%BA%E4%BE%8B%EF%BC%9A"><span class="nav-number">2.1.4.</span> <span class="nav-text">示例：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%93%8D%E5%BA%94%E6%8A%A5%E6%96%87"><span class="nav-number">2.2.</span> <span class="nav-text">响应报文</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%8A%B6%E6%80%81%E8%A1%8C"><span class="nav-number">2.2.1.</span> <span class="nav-text">状态行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%93%8D%E5%BA%94%E5%A4%B4"><span class="nav-number">2.2.2.</span> <span class="nav-text">响应头</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AB%AF%E5%8F%A3%E5%8F%B7"><span class="nav-number">3.</span> <span class="nav-text">端口号</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95"><span class="nav-number">4.</span> <span class="nav-text">请求方法</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="芷若"
      src="/images/touxiang.jpg">
  <p class="site-author-name" itemprop="name">芷若</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">19</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/zhiruo" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhiruo" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">陕ICP备2022001874号 </a>
      <img src="http://www.beian.gov.cn/portal/download" style="display: inline-block;">
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="芷若"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">芷若</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">105k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">1:35</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="//cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js"></script>
<script src="//cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js"></script>
<script src="/js/algolia-search.js"></script>














  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/assets/koharu.model.json"},"display":{"position":"right","width":145,"height":315},"mobile":{"show":true,"scale":0.5},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body>
</html>
